package com.xmkj.bearbiz.pk;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.common.BearBean.CommuniBean;
import com.common.BearMethods.GetCommunicateListMethods;
import com.common.cons.Constans;
import com.common.mvp.BaseMvpActivity;
import com.common.mvp.BasePresenter;
import com.common.retrofit.subscriber.CommonSubscriber;
import com.common.retrofit.subscriber.SubscriberListener;
import com.common.utils.SPUtils;
import com.common.widget.recyclerview.refresh.recycleview.XRecyclerView;
import com.xmkj.bearbiz.R;
import com.xmkj.bearbiz.pk.adaper.ChenLieAdapter;
import com.xmkj.bearbiz.pk.adaper.TuisongAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Create by leo
 * 创建日期：2018/6/26
 * 描述：
 */

public class ShopCommunicationActivity extends BaseMvpActivity {
    @BindView(R.id.tv_sale_skill)
    TextView tvSaleSkill;
    @BindView(R.id.tv_menber_service)
    TextView tvMenberService;
    @BindView(R.id.tv_shop_manage)
    TextView tvShopManage;
    @BindView(R.id.rl_tuisong)
    RelativeLayout rlTuisong;
    @BindView(R.id.recyclerview_tuisong)
    XRecyclerView recyclerviewTuisong;
    @BindView(R.id.rl_chenlie)
    RelativeLayout rlChenlie;
    @BindView(R.id.recyclerview_chenlie)
    XRecyclerView recyclerviewChenlie;


    @Override
    protected BasePresenter createPresenterInstance() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_shop_communication;
    }

    @Override
    protected void onViewCreated() {

    }

    @Override
    protected void doLogicFunc() {
        attachClickListener(tvSaleSkill);
        attachClickListener(tvMenberService);
        attachClickListener(tvShopManage);
        attachClickListener(rlChenlie);
        attachClickListener(rlTuisong);
        gotoHttp();
//        gotoChenLieHttp();
    }


    private void setChenLieReclerview(CommuniBean bean) {
        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerviewChenlie.setLayoutManager(layoutManager);
//        recyclerview.addItemDecoration(new DividerGridItemDecoration(context));
      /*  recyclerview.addItemDecoration(new MarginDecoration(LinearLayoutManager.VERTICAL, (int) SizeUtils.dp2px(context, 1)));
        recyclerview.addItemDecoration(new MarginDecoration(LinearLayoutManager.HORIZONTAL, (int) SizeUtils.dp2px(context, 1)));*/
//        recyclerview.addItemDecoration(new MarginDecoration(LinearLayoutManager.VERTICAL, (int) SizeUtils.dp2px(context, 1)));
        recyclerviewChenlie.setHasFixedSize(true);
        recyclerviewChenlie.setRefreshEnabled(false);
        recyclerviewChenlie.setLoadMoreEnabled(false);
        ChenLieAdapter adapter = new ChenLieAdapter(context, bean.collocation);
//        adapter.setOnItemClickSeclect(this);
        recyclerviewChenlie.setAdapter(adapter);
    }

    private void gotoHttp() {
        CommonSubscriber<CommuniBean> subscriber = new CommonSubscriber<>(new SubscriberListener() {
            @Override
            public void onNext(Object o) {
                CommuniBean bean = (CommuniBean) o;
                setTuiSongReclerview(bean);
                setChenLieReclerview(bean);

            }

            @Override
            public void onError(String e, int code) {
                dismissProgressDialog();
                showToastMsg(e);
            }
        });

//        jpushid = JPushInterface.getRegistrationID(this);
        GetCommunicateListMethods.getInstance().shopCommunicate(subscriber, SPUtils.getShareInt(Constans.UID) + "", SPUtils.getShareString(Constans.HASHID));
        rxManager.add(subscriber);
    }

    private void setTuiSongReclerview(CommuniBean baseListBean) {
        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerviewTuisong.setLayoutManager(layoutManager);
//        recyclerview.addItemDecoration(new DividerGridItemDecoration(context));
      /*  recyclerview.addItemDecoration(new MarginDecoration(LinearLayoutManager.VERTICAL, (int) SizeUtils.dp2px(context, 1)));
        recyclerview.addItemDecoration(new MarginDecoration(LinearLayoutManager.HORIZONTAL, (int) SizeUtils.dp2px(context, 1)));*/
//        recyclerview.addItemDecoration(new MarginDecoration(LinearLayoutManager.VERTICAL, (int) SizeUtils.dp2px(context, 1)));
        recyclerviewTuisong.setHasFixedSize(true);
        recyclerviewTuisong.setRefreshEnabled(false);
        recyclerviewTuisong.setLoadMoreEnabled(false);
        TuisongAdapter adapter = new TuisongAdapter(context, baseListBean.product_push);
//        adapter.setOnItemClickSeclect(this);
        recyclerviewTuisong.setAdapter(adapter);
    }

    @Override
    protected void onViewClicked(View view) {
        if (view.getId() == tvSaleSkill.getId()) {
            Intent intent = new Intent(context, BaseListActivity.class);
            intent.putExtra(BaseListActivity.TYPE, 1);
            startActivity(intent);
        }else if(tvMenberService.getId()==view.getId()){
            Intent intent = new Intent(context, BaseListActivity.class);
            intent.putExtra(BaseListActivity.TYPE, 2);
            startActivity(intent);
        }else if(tvShopManage.getId()==view.getId()){
            Intent intent = new Intent(context, BaseListActivity.class);
            intent.putExtra(BaseListActivity.TYPE, 3);
            startActivity(intent);
        }else if(rlChenlie.getId()==view.getId()){
            Intent intent = new Intent(context, BaseListActivity.class);
            intent.putExtra(BaseListActivity.TYPE, 4);
            startActivity(intent);
        }else if(rlTuisong.getId()==view.getId()){
            Intent intent = new Intent(context, BaseListActivity.class);
            intent.putExtra(BaseListActivity.TYPE, 5);
            startActivity(intent);
        }
    }

    @Override
    protected void setNavigation() {
        setNavigationBack("店铺交流");
    }


    @Override
    public void bindKnife() {
        ButterKnife.bind(this);
    }

}
